home *** CD-ROM | disk | FTP | other *** search
- Path: news.th-darmstadt.de!news
- From: Enno Sandner <enno@intellektik.informatik.th-darmstadt.de>
- Newsgroups: comp.lang.c++
- Subject: Re: Question: references to variables within classes
- Date: Wed, 10 Jan 1996 09:58:36 +0100
- Organization: Fachbereich Informatik, TH Darmstadt
- Message-ID: <30F37FBC.2781E494@intellektik.informatik.th-darmstadt.de>
- References: <DKy0MC.3nA@watserv3.uwaterloo.ca>
- NNTP-Posting-Host: kitz.intellektik.informatik.th-darmstadt.de
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0b4 (X11; I; SunOS 4.1.3 sun4m)
-
- Stephen Bay wrote:
- >
- > Hi,
- >
- > Is it possible in C++ to use variables within a class as parameters for a
- > constructor of an object contained within that class? I've tried compiling the
- > following code and my compiler chokes on the list iter declaration within the
- > class dodo - it doesn't recognize CityList and gives a syntax error. All the
- > other statements compile fine though.
- >
- > -stephen
- >
- > #include "slist.hpp"
- >
- > NISList<int *> CityList;
- > NISListIter<int *> CityListIter(CityList);
- >
- > struct bird
- > {
- > NISList<int *> CityList;
- > NISListIter<int *> CityListIter();
- > };
- >
- > class dodo
- > {
- > public:
- > NISList<int *> CityList;
- > chokes here-> NISListIter<int *> CityListIter(CityList);
- > };
- >
- > main()
- > {
- > NISList<int *> CityList;
- > NISListIter<int *> CityListIter(CityList);
- > };
-
- You have to use the so-called member initializer list to pass the
- list-reference to the iterator, e.g.:
-
- class dodo {
- public:
- NISList<int *> CityList;
- NISListIter<int *> CityListIter;
-
- dodo() : CityListIter(CityList) { ... }
- };
-
- Enno
-